package com.tpo.jnotes.client.lib.util;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

public class BeansUtils
{

    public static Object getBeanProperty( Object bean, String property )
    {
        try
        {
            return BeanUtils.getProperty( bean, property );
        }
        catch( IllegalAccessException e )
        {
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
            e.printStackTrace();
            return null;
        }
        catch( InvocationTargetException e )
        {
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
            e.printStackTrace();
            return null;
        }
        catch( NoSuchMethodException e )
        {
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
            e.printStackTrace();
            return null;
        }
    }

    public static void setProperty( Object bean, String propertyName, Object propertyValue )
    {
        try
        {
            BeanUtils.setProperty( bean, propertyName, propertyValue );
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
        }
        catch( IllegalAccessException e )
        {
            e.printStackTrace();
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
        }
        catch( InvocationTargetException e )
        {
            e.printStackTrace();
            // Logging.fatal("Property " + property + " not found in class " +
            // bean.getClass().getCanonicalName());
        }
    }

}
